package cn.wp.ewallet.wallet.extension.util;

import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.symmetric.DES;
import cn.hutool.crypto.symmetric.SymmetricAlgorithm;

import javax.crypto.spec.DESedeKeySpec;
import java.security.InvalidKeyException;

/**
 * DES加密解密工具
 * Created by zhangyongli on 2020/1/11
 */

public class DesUtil {

    // TODO 密钥需要重新定义

    /**
     * 密钥
     */
    private static String KEY = "qhn!QZ46Mkl./,{}{+_)56QP";

    /**
     * 构建DES
     * @return
     */
    public static DES init() {
        DESedeKeySpec deSedeKeySpec = null;
        try {
            deSedeKeySpec = new DESedeKeySpec(KEY.getBytes());
            //生成密钥
            byte[] key = SecureUtil.generateKey(SymmetricAlgorithm.DES.getValue(), deSedeKeySpec.getKey()).getEncoded();
            //构建
            return SecureUtil.des(key);
        } catch (InvalidKeyException e) {
            e.printStackTrace();
        }
        return null;
    }

}
